#define RCC_APB2ENR (0x40021000 + 0x18)
#define IOPCEN 4
#define GPIOC_CRH (0x40011000 + 4)
#define PC_BASE (0x40011000)
#define GPIO_C_ODR (PC_BASE + 0xc)
#define LED_PC13 (0x42000000+(GPIO_C_ODR - 0x40000000)*32 + 13*4)

extern void LED_Init(void);
extern void LED_ON(void);
extern void LED_OFF(void);
extern void Delay(void);

void led_init()
{
	unsigned int *p = (unsigned int *)RCC_APB2ENR;
	unsigned int temp = *p;
	temp |= 1 << IOPCEN;
	*p = temp;
	
	p = (unsigned int *)GPIOC_CRH;
	temp = *p;
	temp &= ~(0xf << 20);
	temp |= 3 << 20;
	*p = temp;
}

void delay(int s)
{
	while(s--)
	{
		int i = 1000;
		while(i--);
	}
}

void led_on(void)
{
	volatile unsigned int *p = (volatile unsigned int *)LED_PC13;
	*p = 0;
}

void led_off(void)
{
	volatile unsigned int *p = (volatile unsigned int *)LED_PC13;
	*p = 1;
}

void __main(void)
{
	led_init();
	while(1)
	{
		led_on();
		delay(1000);
		led_off();
		delay(1000);
	}
	
	
#if 0
	LED_Init();
	while(1){
		LED_ON();
		Delay();
		LED_OFF();
		Delay();
	}
#endif
}
